/**
 * 转正人员详细信息
 */
import React from 'react';
import { withRouter } from 'umi';
import { connect } from 'umi';
import { Col, Row, Tooltip } from 'antd';
import toNumber from 'lodash/toNumber';
import { statusMap } from './StatusMap';
import NoticeLink from './NoticeLink';
import styles from './index.less';

function TrialCard({ data = {}, location, user }) {
    const { query = {} } = location;
    const { employeeCode } = query;
    const currentUser = user.employeeCode;
    const {
        assessTitle,
        assessPerson,
        assessTime,
        assessResult,
        processId,
        currentStatus,
        currentEmployeeCode,
        periodStart,
        periodEnd
    } = data;
    let linkParams = {
        id: processId
    };
    let isShowBtn = true;

    const assessLevel = toNumber(data.assessLevel) + 1;
    if (assessLevel === 0) {
        linkParams = {
            employeeCode,
            status: currentStatus
        };
        isShowBtn = currentUser === currentEmployeeCode;
    }

    // 根据返回字段展示状态组件
    const {
        background,
        text,
        color,
        pathname = '/office/personnelManagement/onboardAndLeave/informal/process/detail',
        title
    } = statusMap[assessLevel] || {};

    const showStatusText = (
        <div className={styles.footer}>
            <span className={styles.recruitStatus} style={{ background, color }}>
                {text}
            </span>
            {isShowBtn && <NoticeLink params={linkParams} pathname={pathname} title={title} />}
        </div>
    );

    return (
        <div className={styles.wrapper}>
            <div className={styles.titleWrap}>
                <span className={styles.title}>{assessTitle}</span>
                <span>
                    ({periodStart} ~ {periodEnd})
                </span>
                {showStatusText}
            </div>
            <div className={styles.infoContent} style={{ marginBottom: '16px' }}>
                <Row className={styles.infoRow}>
                    <Col span={12}>
                        <span className={styles.label}>评估时间：</span>
                        <span className={styles.value}>{assessTime}</span>
                    </Col>
                    <Col span={12}>
                        <span className={styles.label}>评估人：</span>
                        <span className={styles.value}>
                            <Tooltip title={assessPerson}>{assessPerson}</Tooltip>
                        </span>
                    </Col>
                </Row>
                <Row className={styles.infoRow}>
                    <Col span={12}>
                        <span className={styles.label}>评估结果：</span>
                        <span className={styles.value}>{assessResult || '--'}</span>
                    </Col>
                </Row>
            </div>
        </div>
    );
}

export default withRouter(
    connect(({ user }) => ({
        user: user.currentUser
    }))(TrialCard)
);
